﻿using System.Text;
using System.Collections.Generic;

namespace HEFramework
{
    /// <summary>
    ///
    /// Csv文件创建
    /// 
    /// ----------------------------------------
    /// 作者 hep
    /// 创建时间：2023-12-21 20:28:43
    /// ----------------------------------------
    /// </summary>
    public class FileDownloadCsv
    {
        /// <summary>
        /// 表格数据
        /// </summary>
        public class FileDownloadCsvData
        {
            /// <summary>
            /// AB名
            /// </summary>
            public string ABName0 { get; set; }

            /// <summary>
            /// AB加密名
            /// </summary>
            public string ABName1 { get; set; }
        }

        /// <summary>
        /// 文件名
        /// </summary>
        public string FileName => AssetBundleSettingScriptableObject.Instance.AssetbundleExcelFileName;

        /// <summary>
        /// 数据组
        /// </summary>
        public List<FileDownloadCsvData> Datas { get; set; }

        /// <summary>
        /// Csv导出
        /// </summary>
        /// <param name="_t">导出路径</param>
        public void Export(string _t)
        {
            if (!System.IO.Directory.Exists(_t))
            {
                System.IO.Directory.CreateDirectory(_t);
            }

            StringBuilder builder = new StringBuilder();


            for (int i = 0; i < Datas.Count; ++i)
            {
                builder.AppendLine(Datas[i].ABName0 + $"   [{Datas[i].ABName1}]");
            }

            //创建文件并且写入资源列表标签
            System.IO.File.WriteAllText(_t + "/" + FileName, builder.ToString());
        }
    }
}